package base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Administrator on 2016/7/13.
 */
public abstract class WonderBaseFragment extends Fragment {
    private View layoutView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (layoutView == null) throw new NullPointerException("请调用setContentView");
        return layoutView;
    }

    public void setContentView(View layoutView) {
        this.layoutView = layoutView;

    }

    public void setContentView(int layoutResId) {
        layoutView = View.inflate(getActivity(), layoutResId, null);
    }

    public View findViewById(int resId) {
        if (layoutView == null) throw new NullPointerException("在onCreateView之后必须调用");
        return layoutView.findViewById(resId);
    }

    public View getRootView() {
        return layoutView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        findView();
        initView();

    }

    protected abstract void findView();

    protected abstract void initView();
}
